<?php
/**
 * @purpose: 对“请求”类型中子类型为1(玩游戏邀请)的编码与解码文件
 * @author: Mandel Woo <wuzhijian@snda.com>
 *
 * @memo: 参阅motherboard_typex.php
 */
require_once(dirname(__FILE__)."/../../../models/user/UCModUserInfo.php");


function msg_request_type1_encoder() {
	$fields = array("game_name","game_url","game_pic","game_desc","n_playing");

	foreach($fields as $k => $v) {
		eval("\${$v}=func_get_arg($k);");
	}


	return serialize(array(
			"game_name"  => $game_name,
			"game_url"   => $game_url,
			"game_pic"   => $game_pic,
			"game_desc"  => utf_substr($game_desc, 180), //避免过长
			"n_playing"  => $n_playing,
			));
}

function msg_request_type1_decoder() {
	$fields = array("id","senderid","receiverid","content","createTime","changeFlag","fmt");

	foreach($fields as $k => $v) {
		eval("\${$v}=func_get_arg($k);");
	}

	$data = unserialize($content);
	$game_name = htmlspecialchars(utf_substr($data['game_name'], 20, false));
	$game_url  = $data['game_url'];
	$game_pic  = $data['game_pic'];
	$game_desc = htmlspecialchars($data['game_desc']);
	$n_playing = intval($data['n_playing']);


	$users_infos = UCModUserInfo::getUserInfos(array($senderid, $receiverid), array(USERINFO_NICKNAME,USERINFO_AVATAR_45));

	$seduser_nickname = htmlspecialchars($users_infos[$senderid][USERINFO_NICKNAME]);
	$seduser_nickname == '' && $seduser_nickname = $senderid;

	$sender_url = get_user_home_url($senderid);
	$sender     = "<a href=\"{$sender_url}\" target='_blank'>{$seduser_nickname}</a>";

	if ($fmt == 'line') {
		return sprintf("%s 邀请您一起玩 %s", $sender, $game_name); #输出处，不做html转义


	} else if ($fmt == 'box') {
		$time = UCModMessageMgr::fmtTime($createTime, 2);

		if ($n_playing <= 0) {
			$adv = "";
		} else {
			$adv = "$n_playing 个好友在玩";
		}

		echo <<<HTML
<div class="emailUserList">
	<img src="{$users_infos[$receiverid][USERINFO_AVATAR_45]}" class="avatar-45" />
	<img src="{$users_infos[$senderid][USERINFO_AVATAR_45]}" class="avatar-45" />
	<div class="clear"></div>
</div>
<div class="emailQues">
	<h3 class="game"><span class="r">{$time}</span>{$sender} 邀请你一起玩 <a href="{$game_url}" target="_blank">{$game_name}</a></h3>
	<p><img src="{$game_pic}" id="game_pic" /></p>
	<h3 class="title">内容简介</h3>
	<p>{$game_desc}</p>
	<div class="pd10">{$adv}</div>
	<p><a href="{$game_url}" class="gotoPlay" target="_blank"></a> <a href="javascript:;" id="req_ignore_{$id}" class="txt1">忽略</a>
	</p>
</div>
<script>
scaleImage("game_pic");
function scaleImage(img_id){
	var max_w = 382;
	var img = document.getElementById(img_id);

	if(img.width > max_w){
		img.width  = max_w;
	}
}
</script>
HTML;

		return $html;


	} else {
		return "";
	}
}


